package com.hxit.huaxiamelongarden.controller;

import com.hxit.huaxiamelongarden.domin.dto.UserDto;
import com.hxit.huaxiamelongarden.domin.vo.UserVo;
import com.hxit.huaxiamelongarden.service.UserService;
import com.hxit.huaxiamelongarden.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserController
 * @Author 12694
 * @Date 2025/1/23 17:51
 * @Version 1.0
 **/
@RestController
@Slf4j
@RequestMapping("/profile")
public class UserController {
    @Autowired
    private UserService userService;
    //根据用户id查询个人资料
    @GetMapping
    public Result getUserById(@RequestAttribute("userId") String userId){
        log.info("查询个人资料：userId:{}",userId);
        UserVo userVo = userService.selectById(Integer.parseInt(userId));
        return Result.success(userVo);
    }
    //修改个人资料
    @PutMapping
    public Result updateUser(@RequestBody UserDto userDto,@RequestAttribute("userId") String userId){
        userDto.setUserId(Integer.parseInt(userId));
        log.info("更新个人资料：userDto:{}",userDto);
        userService.updateById(userDto);
        return Result.success();
    }


}
